#ifndef WINDOWSSERVICE_H
#define WINDOWSSERVICE_H

#include <string>
#include <iostream>
#include <Windows.h>

namespace NahidaProject {
	class __declspec(dllexport) WindowsService {
	private:
		std::string name;
		LPSTR Wname;
		bool canPauseContinue;

		SERVICE_STATUS status;
		SERVICE_STATUS_HANDLE statusHandle;

		HANDLE workerPaused;
		HANDLE workerContinued;

		static void WINAPI ServiceMain();
		static void WINAPI ControlHandler(DWORD);
		static DWORD WINAPI WorkerThread(LPVOID lpParam);

		// Set accepted controls
		void SetAcceptedControls(bool _in);

		// Internal start/stop functions
		void Startup();
		void Exit();
		void OnError();

		// Service controller invoked start/stop functions
		void ControlStop();
		void ControlPause();
		void ControlContinue();
		void ControlStopOnPause();

	protected:
		HANDLE stopEvent;
		HANDLE pauseEvent;
		HANDLE continueEvent;

		void SetState(DWORD state);
		static WindowsService* instance;
		virtual DWORD WINAPI Worker(LPVOID) { return ERROR_SUCCESS; }

		void ConfirmPause() { 
			SetEvent(workerPaused); 
		}

		void ConfirmContinue() {
			SetEvent(workerContinued); 
		}

		virtual void OnStartup() {

		};

		virtual void OnPause() {

		};

		virtual void OnContinue() {

		};

		virtual void OnStop() {

		};

		virtual void OnExit() {

		};

		virtual void OnFailedRegistration() { 
			TestStartStop(); 
		}

		void Bump();

	public:
		WindowsService(std::string _name, bool _canPauseContinue);
		void TestStartStop();
		int Run();

	};
}

#endif